package com.example.gzysmartcity.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

import java.io.ByteArrayOutputStream;

public class BitmapUntil {
    //bitmap转化String
    public String BitmapToString(Bitmap b){
        String s="";
        ByteArrayOutputStream bs=new ByteArrayOutputStream();
        b.compress(Bitmap.CompressFormat.PNG,100,bs);
        byte[] bytes=bs.toByteArray();
        s= Base64.encodeToString(bytes,Base64.DEFAULT);
        return s;
    }
    //String转化Bitmap
    public Bitmap StringToBitmap(String s){
        Bitmap b=null;
        try {
            byte[] bytes=Base64.decode(s,Base64.DEFAULT);
            b = BitmapFactory.decodeByteArray(bytes,0,bytes.length);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return b;
    }
}
